/**
 * 更新用户信息
 */
import { getUserInfo } from '../../../model/service/account/userInfo';
import { updateUserInfoService } from '../../../model/service/account/updateInfo';

export default async function updateUserInfo(ctx: Context, next: Next): Promise<void> {
  const { body } = ctx.request;
  // 判断是不是有用户的唯一id
  const { uid } = body;
  const result = await getUserInfo({ uid });
  if (result.length === 0) {
    ctx.api.fail(-1, '找不到该用户的信息，更新失败');
  } else {
    const result = await updateUserInfoService(body);
    ctx.api.success(result, 'sucess')
  }
  return next();
}